package br.com.imob.model.mapper;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.ResultSetExtractor;

import br.com.imob.model.Property;

public class PropertyResultSetExtractor implements ResultSetExtractor< List< Property > > {
	
	@Override
    public List< Property > extractData( ResultSet rs ) throws SQLException, DataAccessException {
        
        List< Property > properties = new ArrayList< Property >();

        while ( rs.next() ){
        	properties.add( fillProperty( rs ) );
        }
        
        return properties;
    }

    public static Property fillProperty( ResultSet rs ) throws SQLException {

    	Property property = new Property();
    	property.setId( rs.getString("CD_ID") );
    	property.setDescription( rs.getString( "DE_DESCRIPTION" ) );
    	property.setPrice( rs.getDouble( "NU_PRICE" ) );
    	property.setCadastre( rs.getTimestamp( "DT_CADASTRE" ) );
    	
        return property;
        
    }
    

}
